ํ…Œ์ผ์œˆ๋“œ ํด๋ž˜์Šค๋„ค์ž„ ๋™์ ์œผ๋กœ ๋ถ€์—ฌํ•˜๊ธฐ

8/6/2025

๋ฌธ์ œ์ƒํ™ฉ

<NoProfile size="..." /> ์ด๋ ‡๊ฒŒ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค๊ณ  ํฌ๊ธฐ๋งŒ ๋”ฐ๋กœ props๋กœ ๋„˜๊ฒจ์ฃผ๋ฉด์„œ ํ•„์š”ํ• ๋•Œ๋งˆ๋‹ค ๋‹ค๋ฅธ ํฌ๊ธฐ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“ค์–ด ํ™œ์šฉํ•˜๋ ค๊ณ  ํ–ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ, 6๋งŒ ์ œ๋Œ€๋กœ ํฌ๊ธฐ๊ฐ€ ์กฐ์ ˆ๋˜๊ณ  ๋‚˜๋จธ์ง€ ๋ชจ๋“  ์ˆซ์ž๋“ค์€ ๋ถ€๋ชจ๊ฐ€ ๊ฐ€์ง„ flex ๋•Œ๋ฌธ์— ๊ฝ‰ ์ฐจ๋ฒ„๋ฆฌ๊ฒŒ ๋๋‹ค.

์ฝ”๋“œ

import NoProfile from "public/no-profile";

export function Chat() {
  return (
    <div className="flex flex-col w-1/6 items-center">
      <div className="flex justify-center">
        <NoProfile size="full" />
      </div>
      <span>username</span>
    </div>
  );
}

export default function ChatList() {
  return (
    <div className="bg-gray-200 mt-6 rounded-xl p-4 grid grid-rows-1">
      <Chat />
    </div>
  );
}
///////
export default function NoProfile({ size }: { size: string }) {
  return (
    <svg
      xmlns="http://www.w3.org/2000/svg"
      fill="none"
      viewBox="0 0 24 24"
      strokeWidth={1.5}
      stroke="currentColor"
      className={`size-${size}`}
    >
      <path
        strokeLinecap="round"
        strokeLinejoin="round"
        d="M17.982 18.725A7.488 7.488 0 0 0 12 15.75a7.488 7.488 0 0 0-5.982 2.975m11.963 0a9 9 0 1 0-11.963 0m11.963 0A8.966 8.966 0 0 1 12 21a8.966 8.966 0 0 1-5.982-2.275M15 9.75a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z"
      />
    </svg>
  );
}

์›์ธ

ํ…Œ์ผ์œˆ๋“œ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” JIT ์ปดํŒŒ์ผ๋Ÿฌ ๋ฐฉ์‹ ๋•Œ๋ฌธ. ํ…Œ์ผ์œˆ๋“œ๋Š” (2.1๋ฒ„์ „ ์ดํ›„๋ถ€ํ„ฐ) ๋ชจ๋“  ๊ฐ€๋Šฅํ•œ ํด๋ž˜์Šค๋“ค์„ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•˜๊ณ , ๋นŒ๋“œ์‹œ์— ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๊ฒƒ๋“ค์„ ์ œ๊ฑฐํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ž‘๋™ํ–ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ง€๊ธˆ์€ ๋ฐ˜๋Œ€๋กœ ์ฝ”๋“œ์— ์ง์ ‘ ์ž‘์„ฑ๋˜์–ด์žˆ๋Š” ํด๋ž˜์Šค๋“ค๋งŒ ์ƒ์„ฑํ•œ๋‹ค.

์ฆ‰, ๋™์ ์œผ๋กœ ํด๋ž˜์Šค๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ• size-${size}์„ ์‚ฌ์šฉํ•˜๋ฉด ๋นŒ๋“œํ•  ๋•Œ ํ…Œ์ผ์œˆ๋“œ ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์œ ํšจํ•œ ํด๋ž˜์Šค๋ช…์ด๋ผ๊ณ  ์•Œ์•„๋ณด์ง€ ๋ชปํ•ด์„œ ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์•„์„œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ.

ํ•ด๊ฒฐ

tailwind.config.ts์— ์„ธ์ดํ”„๋ฆฌ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•ด๋„ ๋œ๋‹ค๊ณ  ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‚˜๋Š” prop mapping ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค.

function Button({ color, children }) {
	const colorVariants = {
	    blue: "bg-blue-600 hover:bg-blue-500",
	    red: "bg-red-600 hover:bg-red-500",  
	};  
	return (
	<button 
		className={`${colorVariants[color]} ...`}
	>
		{children}
	</button>
);}

ํด๋ž˜์Šค๋ช…์„ ๋‹ด๊ณ ์žˆ๋Š” ๊ฐ์ฒด๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•. ๊ฐ์ฒด ์•ˆ์— ์ด๋ฏธ ํ…Œ์ผ์œˆ๋“œ ๋ฌธ๋ฒ•์œผ๋กœ ์ž‘์„ฑ๋œ ํด๋ž˜์Šค๋ช…์ด ์žˆ์–ด์„œ ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ๋นผ๋†“์ง€ ์•Š๊ณ  ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.